package or.exa.cangguan.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import or.exa.cangguan.common.Page;
import or.exa.cangguan.common.Result;
import or.exa.cangguan.entity.vo.EmployeeVo;
import or.exa.cangguan.service.EmployeeService;
import or.exa.cangguan.service.impl.EmployeeServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;


@Slf4j
@RestController
@Api(tags = "员工管理")
public class EmployeeController {

    @Autowired
    private EmployeeService employeeService;


    @ApiOperation(value = "添加员工")
    @PostMapping("/employee/add")
    public Result addEmployee(@RequestBody EmployeeVo employeevo){
        int i = employeeService.addEmployee(employeevo);

        return i>0?Result.ok("添加成功"):Result.ok("添加失败");
    }


    @ApiOperation(value = "查询员工")
    @PostMapping("/employee/search")
    public Result searchEmployee(@RequestBody EmployeeVo employeevo){
        Page page = employeeService.selectEmployee(employeevo);



        return Result.ok(page);
    }



    @ApiOperation(value = "删除员工")
    @PostMapping("/employee/delete/{employeeCode}")
    public Result deleteEmployee(@PathVariable String employeeCode){
        int i = employeeService.deleteEmployee(employeeCode);


        return i>0?Result.ok("删除成功"):Result.ok("删除失败");
    }


    @ApiOperation(value = "修改员工")
    @PostMapping("/employee/update")
    public Result updateEmployee(@RequestBody EmployeeVo employeevo){

        return employeeService.updateEmployee(employeevo)>0?Result.ok("修改成功"):Result.ok("修改失败");
    }



    //查询所有员工名称
    @ApiOperation(value = "查询所有员工名称")
    @PostMapping("/employee/searchName")
    public Result searchEmployeeName(){
        return Result.ok(employeeService.selectName());
    }


}
